#include "job.hpp"
#include "wml_node.hpp"
#include "wml_utils.hpp"

namespace {
std::vector<const_job_type_ptr> all_jobs;
}

void job_type::init(wml::const_node_ptr node)
{
	wml::node::const_child_iterator i1 = node->begin_child("job");
	wml::node::const_child_iterator i2 = node->end_child("job");
	for(; i1 != i2; ++i1) {
		job_type* j = new job_type(i1->second);
		all_jobs.push_back(const_job_type_ptr(j));
	}
}

const_job_type_ptr job_type::get(const std::string& id)
{
	foreach(const const_job_type_ptr& j, all_jobs) {
		if(id == j->id()) {
			return j;
		}
	}

	return const_job_type_ptr();
}

const std::vector<const_job_type_ptr>& job_type::jobs()
{
	return all_jobs;
}

job_type::job_type(wml::const_node_ptr node) : id_(node->attr("id"))
{}

const std::string& job_type::id() const
{
	return id_;
}

variant job::get_value(const std::string& key) const
{
	return variant();
}
